<?php


class ArticlePictureTable extends Doctrine_Table
{   
  public static function getInstance()
  {
    return Doctrine_Core::getTable('ArticlePicture');
  }
  
  public function getBackendListQuery(Doctrine_Query $query)
  {
    $rootAlias = $query->getRootAlias();
    
    $user = sfContext::getInstance()->getUser();

    $query->innerJoin("$rootAlias.article a");
    
    if ($user->hasCredential('editor'))
    {
      $query->andWhere('publisher_id = ?', $user->getAttribute('id'));
    }
    else if ($user->hasCredential('admin'))
    {
      $query->andWhereIn('a.area_id', $user->getAreaIds());
    }

    return $query;
  }
}